<template>
    <el-dialog
      v-model="centerDialogVisible"
      width="30%"
      align-center
      color="white"
      style="     background-color: #7a7e8473;
    "
    >
      <h1 style="color: white;">上架图书信息</h1>
      <el-input type="text" placeholder="请填写书籍名" v-model="bookname"></el-input>
      <el-input type="number" placeholder="请填写书籍分类" v-model="categoryId"></el-input>
      <el-input type="text" placeholder="请填写书籍封面" v-model="cover"></el-input>
      <el-input type="text" placeholder="请填写书籍介绍" v-model="info"></el-input>
      <el-input type="number" placeholder="请填写书籍价格" v-model="inPrice"></el-input>
      <el-input type="number" placeholder="请填写书籍入货数量" v-model="quantity"></el-input>
      <el-input type="text" placeholder="请填写书籍折扣" v-model="discount"></el-input>
      <el-input type="text" placeholder="请填写书籍城市" v-model="city"></el-input>
      <el-input type="number" placeholder="请填写书籍是否为新书（填写1为新书，0为旧书）" v-model="newbook"></el-input>
      <template #footer>
      <span class="dialog-footer">
        <el-button @click="centerDialogVisible = false" style="background-color:rgb(57 175 191 / 48%);color: white;">取消</el-button>
        <el-button
          type=" "
          class="buy"
          @click="addbook()"
          v-if="total != 0"
        >
         确认
        </el-button>
      </span>
    </template>
    </el-dialog>
   
  </template>
  <script>
  export default {
    data(){
        return{
            centerDialogVisible:false,
            bookname:'',
            categoryId:'',
            cover:'',
            info:'',
            inPrice:'',
            quantity:'',
            discount:'',
            city:'',
            newbook:''

        }
    },
    methods:{
        addbook(){
            var data=new FormData()
            data.append('bookname',this.bookname)
            data.append('categoryId',parseFloat(this.categoryId) )
            data.append('cover',this.cover)
            data.append('info',this.info)
            data.append('inPrice',parseFloat(this.inPrice) )
            data.append('quantity',parseFloat(this.quantity) )
            data.append('city',this.city)
            data.append('discount',parseFloat(this.discount) )
            data.append('newbook',parseFloat(this.newbook) )
            this.$axios.post('/addbook',data).then(resp=>{
if(resp.data.code==200){
    this.$message({
        message: "添加成功",
        type: "success",
      });
      this.centerDialogVisible=false
      this.$parent.loadbookslist();
}
            })
        }
    }
  }
  </script>